
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom'
import Page from './page'
import { RouterType } from '../interface'

const Router = ()=> {

    const mapRouter = (routes:RouterType[]) => {
        return routes.map((item, idx) => {
            return item.path ? <Route key={idx} path={item.path} element={item.element}>
                {
                    item.children && mapRouter(item.children)
                }
            </Route> : <Route key={idx} path={item.from as string} element={<Navigate to={item.to as string}></Navigate>}></Route>
        })
    }

    return <BrowserRouter>
        <Routes>
            {
                mapRouter(Page)
            }
        </Routes>
    </BrowserRouter>
}


export default Router